<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<?php $this->load->view('common/head'); ?>

<?php $this->load->view('common/header'); ?>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <?php $this->load->view('common/sidebar'); ?>
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <?php $this->load->view('common/breadcrumbs'); ?>

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">

                <?php $this->load->view('common/set'); ?>

                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <form class="form-inline" action="" method="get">
                            <label class="inline">订单搜索</label>
                            <input type="text" placeholder="输入订单号" name="order_no" id="order_no" value=""
                                   class="form-control">
                            <label class="inline">&nbsp;&nbsp;订单状态：</label>
                            <select id="order_status" name="order_status" class="multiselect select2">
                                <option value=""
                                        <?php if (isset($search) && $search['order_status'] == ""){ ?>selected="selected"<?php } ?>>
                                    全部
                                </option>
                                <option value="-1"
                                        <?php if (isset($search) && $search['order_status'] == -1){ ?>selected="selected"<?php } ?> >
                                    待派单
                                </option>
                                <option value="1"
                                        <?php if (isset($search) && $search['order_status'] == 1){ ?>selected="selected"<?php } ?> >
                                    待服务
                                </option>
                                <option value="5"
                                        <?php if (isset($search) && $search['order_status'] == 5){ ?>selected="selected"<?php } ?> >
                                    已完成
                                </option>
                                <option value="-2"
                                        <?php if (isset($search) && $search['order_status'] == -2){ ?>selected="selected"<?php } ?> >
                                    已失效
                                </option>
                                <option value="6"
                                        <?php if (isset($search) && $search['order_status'] == 6){ ?>selected="selected"<?php } ?> >
                                    已结算
                                </option>
                            </select>
                            <label class="inline">服务时间：<input type="text" class="form-control demo-input starttime"
                                                              name='starttime' placeholder="开始日期" id="test1"
                                                              value="<?php if (isset($search['starttime'])) {
                                                                  echo $search['starttime'];
                                                              } ?>" autocomplete="off"></label>
                            <label class="inline">-<input type="text" class="form-control demo-input endtime"
                                                          name='endtime' placeholder="结束日期" id="test2"
                                                          value="<?php if (isset($search['endtime'])) {
                                                              echo $search['endtime'];
                                                          } ?>" autocomplete="off"></label>
                            <button type="submit" class="btn btn-purple btn-sm">
                                <span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
                                查询
                            </button>
                            <button type="button" class="btn btn-purple btn-sm" id="export">
                                <span class="ace-icon fa fa-plus icon-on-right bigger-110"></span>
                                导出
                            </button>
                            <button type="button" class="btn btn-purple btn-sm" id="add">
                                <span class="ace-icon fa fa-plus icon-on-right bigger-110"></span>
                                新增
                            </button>
                        </form>
                    </div>
                    <div class="col-xs-12" style="margin-top: 15px;">
                        <table class="table table-striped table-bordered">
                            <thead>
                            <tr>
                                <th>出发时间</th>
                                <th>订单ID</th>
                                <th>订单号</th>
                                <th>订单类型</th>
                                <th>订单价格</th>
                                <th>产品</th>
                                <th>订单来源</th>
                                <th>订单状态</th>
                                <th>下单时间</th>
                                <th>接单司机</th>
                                <th>接单时间</th>
                                <th>添加人</th>
                                <th class="center">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php if (isset($orders)) {
                                foreach ($orders as $key => $val) { ?>
                                    <tr>
                                        <td><?= $val['start_time'] ?></td>
                                        <td><?= $val['order_id'] ?></td>
                                        <td><?= $val['external_order_no'] ?></td>
                                        <td class="grouptd">
                                            <span class="label label-sm label-inverse arrowed-in"><?= $val['order_type_name'] ?></span>
                                        </td>
                                        <td><?= $val['order_price'] ?></td>
                                        <!--                                        <td style="width: 250px;">-->
                                        <?//= mb_strimwidth($val['routes'], 0, 60, '...');?><!--</td>-->
                                        <td style="width: 250px;"><?= $val['routes']; ?></td>
                                        <td><?= $val['order_from'] ?? "携程"; ?></td>
                                        <td>
                                            <?php if ($val['order_status'] == -2) { ?>
                                                <span class="label label-danger arrowed-in arrowed-in-right"><?= $val['order_state_name'] ?></span>
                                            <?php } ?>
                                            <?php if ($val['order_status'] == -1) { ?>
                                                <span class="label label-info arrowed-in arrowed-in-right"><?= $val['order_state_name'] ?></span>
                                            <?php } ?>
                                            <?php if ($val['order_status'] == 0) { ?>
                                                <span class="label label-sm label-warning arrowed arrowed-righ"><?= $val['order_state_name'] ?></span>
                                            <?php } ?>
                                            <?php if ($val['order_status'] < 5 && $val['order_status'] > 0) { ?>
                                                <span class="label label-sm label-info arrowed arrowed-righ"><?= $val['order_state_name'] ?></span>
                                            <?php } ?>
                                            <?php if ($val['order_status'] == 5) { ?>
                                                <span class="label label-sm label-success arrowed arrowed-righ"><?= $val['order_state_name'] ?></span>
                                            <?php } ?>
                                            <?php if ($val['order_status'] == 6) { ?>
                                                <span class="label label-sm label-success arrowed arrowed-righ"><?= $val['order_state_name'] ?></span>
                                            <?php } ?>
                                        </td>
                                        <td><?= $val['create_time'] ?></td>
                                        <td><?= $val['user_name'] ?? ""; ?></td>
                                        <td><?= $val['rob_time'] ?></td>
                                        <td><?= $val['admin_name'] ?? "--" ?></td>
                                        <td class="center" style="width: 200px;">
                                            <a href="<?= site_url(X_URL . 'OrderCar/detail/' . $val['order_id']); ?>"
                                               title="订单详情">订单详情</a>
                                            <a href="<?= site_url(X_URL . 'OrderCar/edit/' . $val['order_id']); ?>">修改</a>&nbsp;&nbsp;
                                            <a class="push-order" href="javascript:;"
                                               data-url="<?= site_url(X_URL . 'OrderCar/push_order'); ?>"
                                               data-id="<?php echo $val['order_id']; ?>">群发推送</a>&nbsp;&nbsp;
                                            <a href="<?= site_url(X_URL . 'OrderCar/push_order_user') . "?order_id=" . $val['order_id']; ?>"
                                               data-id="<?php echo $val['order_id']; ?>">定向推送</a>&nbsp;&nbsp;
                                            <a class="cancel-order" href="javascript:;"
                                               data-url="<?= site_url(X_URL . 'OrderCar/order_audit'); ?>"
                                               data-id="<?php echo $val['order_id']; ?>" data-status="2">取消</a>&nbsp;&nbsp;
                                            <a href="<?= site_url(X_URL . 'OrderCar/order_settled'); ?>?order_id=<?= $val['order_id'] ?>">标记已结算</a>&nbsp;&nbsp;
                                            <a class="del" href="javascript:;"
                                               val="<?= site_url(X_URL . 'OrderCar/del'); ?>"
                                               data-id="<?php echo $val['order_id']; ?>" title="删除">删除</a>&nbsp;&nbsp;
                                            <?php if (in_array($val['order_status'], [5, 6])) { ?>
                                                <a href="<?= site_url(X_URL . 'OrderCar/appraise/' . $val['order_id']); ?>"
                                                   title="查看评价">查看评价</a>&nbsp;
                                            <?php } ?>
                                            <?php if ($val['order_status'] == -2) { ?>
                                                <a href="<?= site_url(X_URL . 'OrderCar/appraise/' . $val['order_id']); ?>"
                                                   title="查看评价">查看取消原因</a>&nbsp;
                                            <?php } ?>
                                        </td>
                                    </tr>
                                <?php }
                            } ?>
                            </tbody>
                        </table>
                        <?php if ($pagination) { ?>
                            <ul class="pagination"><?= $pagination; ?></ul><?php } ?>
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div><!-- /.main-content -->

    </div><?php $this->load->view('common/footer'); ?>


    <?php $this->load->view('common/footerjs'); ?>
    <?php echo admin_js_url('laydate'); ?>
    <!-- inline scripts related to this page -->
    <script type="text/javascript">

        $(function () {
            //执行一个laydate实例
            laydate.render({
                elem: '#test1' //指定元素
            });
            laydate.render({
                elem: '#test2' //指定元素
            });
            $("#officialnews ul").html('<div class="ace-icon fa fa-spinner fa-spin orange"></div>');
        })
        $("#add").click(function () {
            window.location.href = "add";
        });
        $(".del").click(function () {
            var url = $(this).attr('val');
            var order_id = $(this).attr('data-id');
            layer.confirm('您确定要删除该订单么？', {
                btn: ['删除', '取消'] //按钮
            }, function () {
                $.ajax({
                    type: "post",
                    url: url,
                    data: {'order_id': order_id, 'csrf_test_name': ci_csrf_token()},
                    dataType: "JSON",
                    success: function (msg) {
                        if (msg.status == 1) {
                            layer.msg(msg.info, {
                                time: 1000, //1s后自动关闭
                                shade: 0.1,
                                icon: 1
                            }, function () {
                                window.location.reload();
                            });
                        } else {
                            layer.msg(msg.info, {
                                time: 1000, //1s后自动关闭
                                shade: 0.1
                            });
                            return false;
                        }
                    }
                })
            }, function () {
            });
        });
        $(".push-order").click(function () {
            var url = $(this).attr('data-url');
            var order_id = $(this).attr('data-id');
            layer.confirm('您确定要推送该订单么？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                $.ajax({
                    type: "post",
                    url: url,
                    data: {'order_id': order_id, 'csrf_test_name': ci_csrf_token()},
                    dataType: "JSON",
                    success: function (msg) {
                        if (msg.status == 1) {
                            layer.msg(msg.info, {
                                time: 1000, //1s后自动关闭
                                shade: 0.1,
                                icon: 1
                            }, function () {
                                window.location.reload();
                            });
                        } else {
                            layer.msg(msg.info, {
                                time: 1000, //1s后自动关闭
                                shade: 0.1
                            });
                            return false;
                        }
                    }
                })
            }, function () {
            });
        });
        $(".cancel-order").click(function () {
            var url = $(this).attr('data-url');
            var order_id = $(this).attr('data-id');
            var order_audit = $(this).attr('data-status');
            layer.confirm('您确定要取消该订单么？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                $.ajax({
                    type: "post",
                    url: url,
                    data: {'order_id': order_id, 'order_audit': order_audit, 'csrf_test_name': ci_csrf_token()},
                    dataType: "JSON",
                    success: function (msg) {
                        if (msg.status == 1) {
                            layer.msg(msg.info, {
                                time: 1000, //1s后自动关闭
                                shade: 0.1,
                                icon: 1
                            }, function () {
                                window.location.reload();
                            });
                        } else {
                            layer.msg(msg.info, {
                                time: 1000, //1s后自动关闭
                                shade: 0.1
                            });
                            return false;
                        }
                    }
                })
            }, function () {
            });
        });
        $("#export").click(function () {
            var order_no = $("#order_no").val();
            var test1 = $("#test1").val();
            var test2 = $("#test2").val();
            var order_status = $("#order_status").val();
            var url = baseurl + "index.php/manage/OrderCar/export_excel";
            window.location.href = url + "?order_no=" + order_no + "&order_status=" + order_status + "&starttime=" + test1 + "&endtime=" + test2;
        });
    </script>
</body>
</html>
